<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");
require_once("../_inc/_mbAppDomValue.php");
require_once("domainFunction.php");

$errMsg = "";
$domain = sxREQUEST("domain");
$entity = sxREQUEST("entity");
$attribute = sxREQUEST("attribute");
$description = sxREQUEST("description");
$note = sxREQUEST("note");
$type = sxREQUEST("type");
$length = sxREQUEST("length");
$decimals = sxREQUEST("decimals");
$enumerable = sxREQUEST("enumerable");
$frequent = sxREQUEST("frequent");
if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "save"){
	$errMsg .= domainUpd();	
}
if(isset($_REQUEST["reqtype"]) && $_REQUEST["reqtype"] == "delete"){
	$errMsg .= domainDel();	
}
if(isset($_REQUEST["ent"])){
	$entity = $_REQUEST["ent"];
}
if(isset($_REQUEST["dom"]) || isset($_REQUEST["domain"])) {
	$domain = (isset($_REQUEST["dom"]))?$_REQUEST["dom"]:$_REQUEST["domain"];
	$sSQL = "SELECT * FROM domain WHERE domain='".$domain."'";
	$objSDAO->query($sSQL,'dom');
	if ($row = $objSDAO->fetch('dom')) {
		$entity = $row["lookup_entity"];
		$attribute = $row["lookup_attribute"];
		$description = $row["description"];
		$note = $row["note"];
		$type = $row["type"];
		$length = $row["length"];
		$decimals = $row["decimals"];
		$enumerable = $row["enumerable"];
		$frequent = $row["frequent"];
	} else {
			$url = $_SESSION[USEROBJ]->getHistory(-1, true);
			serverRedir($url);
		}		
}
//RS elenco entity
$sSQL = "SELECT * FROM entity ORDER BY entity";
if(!$queryAttr = $objSDAO->query($sSQL,'entList',array("contOnErr"=>true))){
	$errMsg .= $objSDAO->error;
	$errCode .= $objSDAO->errno;
}

if($entity != ""){
	//RS elenco attribute
	$sSQL = "SELECT * FROM attribute WHERE entity='$entity' ORDER BY attribute";
	if(!$queryAttr = $objSDAO->query($sSQL,'attrList',array("contOnErr"=>true))){
		$errMsg .= $objSDAO->error;
		$errCode .= $objSDAO->errno;
	}
}
//output HTML
$aOpz = array("kMenu"=>'dam.dom');
echo(headerHTML($aOpz));
?>
<script language="JavaScript" type="text/javascript" src="../../_jsc/ajax.js"></script>
<script language="JavaScript" type="text/javascript" src="../../_jsc/form.js"></script>      
<?php
echo(bodyHTML($aOpz));
echo("<table width=\"100%\" cellpadding=\"03\" cellspacing=\"0\">\n<tr>\n<td>\n");
echo("<form name=\"objFrm\" id=\"objFrm\" action=\"domainView.php\" method=\"POST\">");
echo("<input type=\"hidden\" name=\"reqtype\" id=\"reqtype\" value=\"save\">");
echo("<input type=\"hidden\" name=\"xsn\" id=\"xsn\" value=\"".XSN."\">");
echo("<input type=\"hidden\" name=\"type\" id=\"type\" value=\"".$type."\">");
//output comandi
$aCmd = array();
$aCmd["attdom"] = array("pag"=>"attrDomList.php?dom=$domain",
										"title"=>_t("Associated attributes"),
										"text"=>_t("attributes"),
										"perm"=>"upddom","align"=>"L");
$aCmd["ins"] = array("pag"=>"domainMod.php?dom=$domain",
										"title"=>_t("change domain"),
										"text"=>_t("modifiy"),
										"perm"=>"upddom");
$aCmd["del"] = array("pag"=>"javascript:confirmDelete()",
										"title"=>_t("delete domain"),
										"text"=>_t("delete"),
										"perm"=>"upddom");
if ($enumerable == 'Y')	{									
	$aCmd["val"] = array("pag"=>"domainValueList.php?dom=$domain",
										"title"=>_t("List of domain values"),
										"text"=>_t("domain values")
										);
}
$aCmd["back"] = array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1)
										);
echo(commandsHTML($aCmd));	
//form inserimento dati
echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
echo("<tr>" .
			"<td class=\"titl01\" colspan=\"2\">"._t("Domain")."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\" width=\"20%\">"._t("Domain")."</td>" .
			"<td class=\"text01\">$domain<input class=\"inpt01\" type=\"hidden\" name=\"domain\" id=\"domain\" value=\"$domain\"></td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Description")."</td>" .
			"<td class=\"text01\">".sxHE($description)."</td>" .
		"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Type")."</td>" .
			"<td class=\"text01\">");
echo($type);
echo("</td></tr>\n");
echo("<tr>" .
	"<td class=\"labl01\">"._t("Length")."</td>" .
	"<td class=\"text01\">$length</td>" .
"</tr>\n");
echo("<tr>" .
	"<td class=\"labl01\">"._t("Decimals")."</td>" .
	"<td class=\"text01\">$decimals</td>" .
"</tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Enumerable")."</td>" .
			"<td class=\"text01\">");
echo(isset($aEnum[$enumerable])?$aEnum[$enumerable]:"");
echo("</td></tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Look-up entity")."</td>" .
			"<td class=\"text01\">");
echo("$entity");		
echo("</td></tr>\n");

echo("<tr>" .
			"<td class=\"labl01\">"._t("Look-up attribute")."</td>" .
			"<td class=\"text01\">");
if($entity != ""){
	echo("$attribute");
}
echo("</td></tr>\n");
echo("<tr>" .
			"<td class=\"labl01\">"._t("Frequent")."</td>" .
			"<td class=\"text01\">");
echo($frequent=='Y')?'yes':'no';
echo("</td></tr>\n");
echo("<tr>" .
	"<td class=\"labl01\">"._t("Note")."</td>" .
	"<td class=\"text01\"><pre class=\"text01\">".sxWW(sxHE($note))."</pre></td>" .
"</tr>\n");
echo("</table>");

echo(commandsHTML($aCmd));
echo("</form>");
echo("</td>\n</tr>\n</table>\n");
echo(footerHTML());
